package ihm.panel;

import java.awt.Graphics;
import java.awt.Image;

import javax.swing.JPanel;

/**
 * JPanel affichant des images BMP à intervals réguliers, utilisé par BMPPlayer.
 */
class ImagePanel extends JPanel {

	private static final long serialVersionUID = 1L;

	public Image myimg = null;

	/**
	 * Constructeur.
	 */
	public ImagePanel() {
		setLayout(null);
		setSize(320, 240);
	}

	/**
	 * Afficher une nouvelle image.
	 * @param img
	 */
	public void setImage(Image img) {
		this.myimg = img;
		repaint();
	}

	@Override
	public void paint(Graphics g) {
		if (myimg != null) {
			g.drawImage(myimg, 0, 0, this);
		}
	}
	
	/**
	 * Optimisation des images à afficher
	 * @param image
	 * @return BufferedImage
	 */
	/*private BufferedImage toCompatibleImage(BufferedImage image) {
		// obtain the current system graphical settings
		GraphicsConfiguration gfx_config = GraphicsEnvironment.
			getLocalGraphicsEnvironment().getDefaultScreenDevice().
			getDefaultConfiguration();

		// if image is already compatible and optimized for current system settings, simply return it
		if (image.getColorModel().equals(gfx_config.getColorModel()))
			return image;

		// image is not optimized, so create a new image that is
		BufferedImage new_image = gfx_config.createCompatibleImage(
				image.getWidth(), image.getHeight(), image.getTransparency());

		// get the graphics context of the new image to draw the old image on
		Graphics2D g2d = (Graphics2D) new_image.getGraphics();

		// actually draw the image and dispose of context no longer needed
		g2d.drawImage(image, 0, 0, null);
		g2d.dispose();

		// return the new optimized image
		return new_image; 
	}*/
	
}
